import logging
import time
import unittest
from webAutomation import utils
from webAutomation.page.home_pages import HomeProxy
from webAutomation.page.login_page import LoginProxy
from webAutomation.page.overview_of_battery_page import OverviewOfBatteryProxy
from webAutomation.utils import DriverUtil


class TestAddCabinet(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        cls.login_proxy = LoginProxy()
        cls.home_proxy = HomeProxy()
        cls.overview_of_battery_proxy = OverviewOfBatteryProxy()

    @classmethod
    def tearDown(self) -> None:
        DriverUtil.quit_driver()

    def test01_add_cabinet_success(self):
        try:
            # 登录
            self.login_proxy.login("admin", "123")
            # 打开电池概览页面
            self.home_proxy.open_overview_of_battery()
            # 添加电池
            self.overview_of_battery_proxy.add_battery(battery_manufacturer="光明区打样中心", battery_sn="BT104802512SZHL210405999")
            time.sleep(3)
            # 断言
            assert_result = utils.exit_text("BT104802512SZHL210405999")
            self.assertTrue(assert_result)


        # 捕捉异常
        except Exception as e:
            # 截图
            utils.screenshot(self)
            # 输出日志
            logging.info("添加电池出现异常：{}".format(e))
            raise